package com.company.设计模式.单例模式;

/**
 * @Classname Singleton6
 * @Description 枚举类实现
 * @Date 2021/9/10 10:57
 * @Created by ylr
 */
public class Singleton6 {

    private static enum SingletonEnum{
        INSTANCE;

        private Singleton6 uniqueInstance;
        SingletonEnum(){
            System.out.println("初始化!");
            uniqueInstance = new Singleton6();
        }


        private Singleton6 getUniqueInstance(){
            return uniqueInstance;
        }
    }

    private static Singleton6 getInstance(){

        return SingletonEnum.INSTANCE.getUniqueInstance();
    }

    public void sout(){
        System.out.println(this.toString()+"   实力方法!");
    }

    public static void main(String[] args) {
        Singleton6 instance1 = Singleton6.getInstance();
        Singleton6 instance2 = Singleton6.getInstance();
        Singleton6 instance3 = Singleton6.getInstance();
        instance1.sout();
        instance2.sout();
        instance3.sout();


    }

}
